#include<bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'
#define REP(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define PER(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)

template<typename T=int>
inline T read() {
    T x;
    cin >> x;
    return x;
}

using pii=pair<int, int>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    vector<pii> a(read());
    for (auto &p:a) {
        cin >> p.first >> p.second;
    }
    sort(a.begin(), a.end(), [](const pii &p, const pii &q) -> bool {
        return p.second < q.second;
    });
    int tot = 0, start = 0;
    for (auto &p:a) {
        if (p.first >= start) {
            ++tot;
            start = p.second;
        }
    }
    cout << tot << endl;
    return 0;
}